/**
 * 
 */
package com.jonosoft.photocast.viewer.web.client.photocast;

import java.util.Date;

import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;

/**
 * TODO Add description PhotocastItem (com.jonosoft.photocast.viewer.web.client.PhotocastItem)
 *
 * @author jon
 *
 */
public class PhotocastItem extends PhotocastObject {
	
	private interface Keys {
		public static final String THUMBNAIL_URL = "iphoto:thumbnail";
		public static final String CATEGORY = "category";
		public static final String DESCRIPTION = "description";
		public static final String TITLE = "title";
		public static final String PHOTO_DATE = "iphoto:photoDate";
		public static final String PUBLISH_DATE = "pubDate";
		public static final String GUID = "guid";
		public static final String CROP_DATE = "iphoto:cropDate";
		public static final String LINK = "link";
		public static final String ENCLOSURE = "enclosure";
		public static final String CONTENT = "content";
	}
	
	public String getThumbnailURL() {
		return JSONStringValueOrNull((JSONString) jsonRep.get(Keys.THUMBNAIL_URL));
	}
	
	public String getCategory() {
		return JSONStringValueOrNull((JSONString) jsonRep.get(Keys.CATEGORY));
	}
	
	public String getDescription() {
		return JSONStringValueOrNull((JSONString) jsonRep.get(Keys.DESCRIPTION));
	}
	
	public String getTitle() {
		return JSONStringValueOrNull((JSONString) jsonRep.get(Keys.TITLE));
	}
	
	public Date getPhotoDate() {
		return DateValueOrNull((JSONString) jsonRep.get(Keys.PHOTO_DATE));
	}
	
	public Date getPublishDate() {
		return DateValueOrNull((JSONString) jsonRep.get(Keys.PUBLISH_DATE));
	}
	
	private JSONObject getGuidEnclosure() {
		JSONObject guidEnclosure = (JSONObject) jsonRep.get(Keys.GUID);
		
		if (guidEnclosure == null)
			jsonRep.put(Keys.GUID, guidEnclosure = new JSONObject());
		
		return guidEnclosure;
	}
	
	public String getGuid() {
		return JSONStringValueOrNull((JSONString) getGuidEnclosure().get(Keys.CONTENT));
	}
	
	public Date getCropDate() {
		return DateValueOrNull((JSONString) jsonRep.get(Keys.CROP_DATE));
	}
	
	/**
	 *	{
	 *		"iphoto:thumbnail":"http://web.mac.com/skater0i/iPhoto/landon-pics-for-web/726DEC06-4E83-4DD8-9188-AD7569174B01.jpg?transform=medium",
	 *		"category":["Landon","Jon","Pics","Web","Kelling","for"],
	 *		"description":"<p><a href=\"http://web.mac.com/skater0i/iPhoto/landon-pics-for-web/726DEC06-4E83-4DD8-9188-AD7569174B01.jpg\"><img src=\"http://web.mac.com/skater0i/iPhoto/landon-pics-for-web/726DEC06-4E83-4DD8-9188-AD7569174B01.jpg?transform=medium\" alt=\"photo\" title=\"Baby's Ultrasound at 8 weeks\" style=\"float:left; padding-right:10px; padding-bottom:10px;\"/></a>Baby's Ultrasound at 8 weeks</p><br clear=all>",
	 *		"title":"Ultrasound at 8 weeks",
	 *		"iphoto:photoDate":"Sat, 11 Feb 2006 17:10:13 GMT",
	 *		"pubDate":"Wed, 06 Sep 2006 13:08:37 GMT",
	 *		"guid":
	 *			{
	 *				"content":"726DEC06-4E83-4DD8-9188-AD7569174B01",
	 *				"isPermaLink":"false"
	 *			},
	 *		"iphoto:cropDate":"Wed, 06 Sep 2006 13:01:03 GMT",
	 *		"link":"http://web.mac.com/skater0i/iPhoto/landon-pics-for-web/726DEC06-4E83-4DD8-9188-AD7569174B01.jpg",
	 *		"enclosure":
	 *			{
	 *				"url":"http://web.mac.com/skater0i/iPhoto/landon-pics-for-web/726DEC06-4E83-4DD8-9188-AD7569174B01.jpg",
	 *				"length":"824321",
	 *				"type":"image/jpeg"
	 *			}
	 *	}
	 *
	 * @return
	 */
	public String getLink() {
		return JSONStringValueOrNull((JSONString) jsonRep.get(Keys.LINK));
	}
	
	public String getEnclosure() {
		return JSONStringValueOrNull((JSONString) jsonRep.get(Keys.ENCLOSURE));
	}
	
}
